﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using com.dz.entity;
using com.dz.dataaccess;
using com.dz.common;

namespace com.dz.components
{
    public class BookCommendManager
    {
        BookCommendDao m_book_commend_dao = new BookCommendDao();
          /// <summary>
        /// 分页获取推荐列表
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="totalCount"></param>
        /// <param name="commendType"></param>
        /// <param name="pageType"></param>
        /// <returns></returns>
        public DataSet GetCommendListByPage(int pageIndex, int pageSize, out int totalCount, Consts.CommendType commendType, Consts.PageType pageType)
        {
            totalCount = 0;
            try
            {
                return m_book_commend_dao.GetCommendListByPage(pageIndex, pageSize, out totalCount, commendType, pageType);
            }
            catch (Exception ex)
            {
                LogHelper.Error("分页获取推荐列表信息失败" + ex.ToString());
                return null;
            }
        }

        /// <summary>
        /// 添加首页封面推荐
        /// </summary>
        /// <param name="i_script"></param>
        /// <param name="commendType"></param>
        /// <returns></returns>
        public string AddBookCommendByBookId(string i_script,Consts.CommendType commendType)
        {
            long t_book_id = 0;
            if (!long.TryParse(i_script, out t_book_id))
                t_book_id = 0;
            if (t_book_id == 0)
                return "参数错误";

            int ret = AddBookCommend(t_book_id, commendType);
            if (ret == Consts.Successed)
                return "操作成功";
            return "操作失败";
        }

        /// <summary>
        /// 取消推荐
        /// </summary>
        /// <param name="i_script"></param>
        /// <param name="commendType"></param>
        /// <returns></returns>
        public string DeleteBookComendByBookId(string i_script, Consts.CommendType commendType)
        {
            long t_book_id = 0;
            if (!long.TryParse(i_script, out t_book_id))
                t_book_id = 0;
            try
            {
                int ret= m_book_commend_dao.DeleteBookCommend(t_book_id, commendType);
                if (ret == Consts.Successed)
                    return "操作成功";
                return "操作失败";
            }
            catch (Exception ex)
            {
                LogHelper.Error("删除推荐失败" + ex.ToString());
                return "操作失败";
            }
        }


           /// <summary>
        /// 添加书籍推荐
        /// </summary>
        /// <param name="bookId"></param>
        /// <param name="commendType"></param>
        /// <returns></returns>
        public int AddBookCommend(long bookId, Consts.CommendType commendType)
        {
            try
            {
                int ret = m_book_commend_dao.AddBookCommend(bookId, commendType);
                if (ret != Consts.Failed)
                    return Consts.Successed;
                return Consts.Failed;
            }
            catch (Exception ex)
            {
                LogHelper.Error("添加推荐书籍失败" + ex.ToString());
                return Consts.Failed;
            }
        }

      /// <summary>
      /// 删除推荐书籍
      /// </summary>
      /// <param name="bookId"></param>
      /// <param name="commendType"></param>
      /// <returns></returns>
        public int DeleteBookCommend(int bookId, Consts.CommendType commendType)
        {
            try
            {
                int ret = m_book_commend_dao.DeleteBookCommend(bookId, commendType);
                if (ret != Consts.Failed)
                    return Consts.Successed;
                return Consts.Failed;
            }
            catch (Exception ex)
            {
                LogHelper.Error("删除推荐书籍失败" + ex.ToString());
                return Consts.Failed;
            }

        }
    }
}
